<template>
	<view class="list">
		<view class="fixbg" :style="{ backgroundImage: 'url('+ playlist.coverImgUrl +')'}"></view>
		<musicHeader title="歌单" :icon="true" color="white"></musicHeader>
		<view class="container" v-show="!isShow">
			<scroll-view scroll-y="true">
				<view class="list-head">
					<view class="list-head-img">
						<image :src="playlist.coverImgUrl" mode=""></image>
						<text class="iconfont icon-yousanjiao">
							{{ playlist.playCount | formatCount }}
						</text>
					</view>
					<view class="list-head-text">
						<view>{{ playlist.name }}</view>
						<view>
							<image :src="playlist.creator.avatarUrl" mode=""></image>
							<text>{{ playlist.creator.nickname }}</text>
						</view>
						<view>{{ playlist.description }}</view>
					</view>
				</view>
				<!-- #ifdef MP-WEIXIN -->
				<button class="list-share" open-type="share">
					<text class="iconfont icon-fenxiang"></text> 分享给微信好友
				</button>
				<!-- #endif -->
				<view class="list-music">
					<view class="list-music-title">
						<text class="iconfont icon-bofang1"></text>
						<text>播放全部</text>
						<text>(共{{ playlist.trackCount }}首)</text>
					</view>
					<view class="list-music-item" v-for="(item,index) in playlist.tracks" :key="item.id" @tap="handleToDetail(item.id)">
						<view class="list-music-top">{{ index + 1 }}</view>
						<view class="list-music-song">
							<view>{{ item.name }}</view>
							<view>
								<image v-if="privileges[index].fee == 1" src="../../static/dujia.png" mode=""></image>
								<image v-if="privileges[index].maxbr == 999000" src="../../static/sq.png" mode="">
								</image>
								{{ item.ar[0].name }} - {{ item.name }}
							</view>
						</view>
						<text class="iconfont icon-bofang"></text>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>


<script>
	import musicHeader from '../../components/musicHeader.vue';
	import {
		list
	} from '../../common/api.js';
	export default {
		data() {
			return {
				playlist: {
					coverImgUrl: '',
					trackCount: '',
					creator: ''
				},
				privileges: [],
				isShow: true
			}
		},
		components: {
			musicHeader
		},
		onLoad(options) {
			uni.showLoading({
				title: 'loading...'
			});
			let listId = options.listId;
			list(listId).then((res) => {
				// console.log(res);
				if (res.data.code == '200') {
					this.playlist = res.data.playlist;
					this.privileges = res.data.privileges;
					this.$store.commit('INIT_CHANGE', this.playlist.trackIds);
					this.isShow = false
					uni.hideLoading()
				}
			});
		},
		methods: {
			handleToDetail(songId) {
				uni.navigateTo({
					url: '/pages/detail/detail?songId=' + songId
				});
			}
		},
	}
</script>

<style lang="scss" scoped>
	@import '../../static/iconfont/iconfont.css';

	.list-head {
		display: flex;
		margin: 30rpx;

		.list-head-img {
			width: 265rpx;
			height: 265rpx;
			border-radius: 15rpx;
			margin-right: 40rpx;
			overflow: hidden;
			position: relative;

			image {
				width: 100%;
				height: 100%;
			}

			text {
				position: absolute;
				font-size: 26rpx;
				color: white;
				right: 8rpx;
				top: 8rpx;
			}
		}

		.list-head-text {
			flex: 1;
			font-size: 24rpx;
			color: #ffffff;

			image {
				width: 52rpx;
				height: 52rpx;
				border-radius: 50%;
			}

			view:nth-child(1) {
				font-size: 34rpx;
				color: #ffffff;
			}

			view:nth-child(2) {
				display: flex;
				align-items: center;
				margin: 30rpx 0;

				text {
					margin-left: 15rpx;
				}

			}

			view:nth-child(3) {
				display: -webkit-box;
				line-height: 38rpx;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 3;
				overflow: hidden;
			}
		}
	}

	.list-share {
		width: 330rpx;
		height: 74rpx;
		margin: 0 auto;
		background: rgba(0, 0, 0, 0.4);
		border-radius: 37rpx;
		color: white;
		text-align: center;
		line-height: 74rpx;
		font-size: 24rpx;
	}

	.list-music {
		background: white;
		border-radius: 50rpx;
		margin-top: 40rpx;
		overflow: hidden;

		.list-music-title {
			height: 50rpx;
			margin: 30rpx 0 70rpx 22rpx;

			text:nth-child(1) {
				font-size: 45rpx;
			}

			text:nth-child(2) {
				font-size: 34rpx;
				margin: 0 10rpx 0 20rpx;
			}

			text:nth-child(3) {
				font-size: 28rpx;
				color: #b2b2b2;
			}
		}

		.list-music-item {
			display: flex;
			margin: 0 32rpx 66rpx 46rpx;
			align-items: center;
			color: #959595;

			.list-music-top {
				width: 58rpx;
				font-size: 30rpx;
				line-height: 30rpx;
				color: #979797;
			}

			.list-music-song {
				flex: 1;
				line-height: 40rpx;

				view:nth-child(1) {
					font-size: 28rpx;
					color: black;
					width: 70vw;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}

				view:nth-child(2) {
					align-items: center;
					font-size: 20rpx;
					width: 70vw;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;

					image {
						width: 32rpx;
						height: 20rpx;
						margin-right: 10rpx;
						// flex-shrink: 0;
					}
				}
			}

			text {
				font-size: 50rpx;
			}
		}
	}
</style>